package com.meicunbing.viberplugin.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {
	
	//数据库名称
	private final static String DATABASE_NAME = "viber";
	//数据库版本号
	private final static int DATABASE_VERSION = 1;
	public static final String DATABASE_TABLE = "city_code";
	 
	//数据表创建SQL语句
	private static final String DATABASE_CREATE = "create table "+DATABASE_TABLE+" (_id integer primary key autoincrement, city varchar(16) not null, code char(9) not null);";

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		//执行创建数据库SQL语句
		db.execSQL(DATABASE_CREATE);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//判断数据库是否存在
		db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
		onCreate(db);
	}

}
